package com.github.pig.admin.controller;

import com.github.pig.admin.model.entity.SysCommunityUser;
import com.github.pig.admin.service.sys.SysCommunityUserService;
import com.github.pig.admin.service.sys.SysUserService;
import com.github.pig.common.vo.UserVO;
import com.github.pig.common.web.BaseController;
import io.jsonwebtoken.Claims;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/sysCommunityUser")
public class SysCommunityUserController extends BaseController {

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysCommunityUserService sysCommunityUserService;

    /**
     * 根据当前登录用户获取到所属小区id集合
     */
    public List getCurrentUserCommunityId(UserVO userVO) {


        // 获取到用户id
        Integer userId = userVO.getUserId();
        // 根据用户id获取到用户小区关联集合
        List<SysCommunityUser> list = sysCommunityUserService.getCurrentUserCommunityId(userId);
        // 新建一个集合以便存放用户所属小区id
        List newList = new ArrayList();
        // 判断是否为空
        if(list == null || list.size() == 0){

            return newList;
        }
        // 遍历用户小区关联集合
        for(SysCommunityUser item : list){
            // 获取到小区id
            String communityId = item.getCommunityId();
            if(StringUtils.isNotEmpty(communityId)){
                newList.add(communityId);
            }
        }
        // 返回
        return newList;
    }
}
